﻿using MediatR;
using MES.Process.API.Application.Command.工序分类命令;
using MES.Process.API.Application.Command.工序命令;
using MES.Process.API.Application.Command.工艺命令;
using MES.Process.Domain;
using MES.Process.Dto;
using MES.Process.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MES.Process.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcessController : ControllerBase
    {
        private readonly ILogger<ProcessController> logger;
        private readonly IMediator mediator;
        public ProcessController(ILogger<ProcessController> logger, IMediator mediator = null)
        {
            this.logger = logger;
            this.mediator = mediator;
        }

        /// <summary>
        /// 工序分类添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> ProcessTypeAdd(ProcessTypeAddCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 工序分类查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<APIPaging<ProcessType>>> ProcessTypeQuery([FromQuery]ProcessTypeQueryCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 工序分类编辑（删除+修改）
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> ProcessTypeEdit(ProcessTypeEditCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 工序添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> ProcessAdd(ProcessAddCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 工序查询列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<APIPaging<ProcessCartfsDto>>> ProcessDtoQuery([FromQuery]ProcessDtoQueryCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 编辑删除工序
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> ProcessEdit(ProcessEditCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 工艺添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CraftsAdd(CraftsAddCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 工艺列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<APIPaging<Crafts>>> CraftsQuery([FromQuery]CraftsQueryCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 工艺编辑
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CraftsEdit(CraftsEditCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取工艺所用有的工序
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<ProcessByidDto>>> ProcessCratfs([FromQuery] ProcessCratfsCommand request) 
        {
            return await mediator.Send(request);
        }
    }
}
